package com.ChenYaRou.www.dao.impl;

import com.ChenYaRou.www.dao.TicketShopDao;
import com.ChenYaRou.www.po.TicketShop;
import com.ChenYaRou.www.utils.GenerateSql;
import com.ChenYaRou.www.utils.JdbcUtil;

import java.sql.SQLException;
import java.util.List;

/**
 * @ClassName TicketShopDaoImpl
 * @Description TODO
 * @Author 86183
 * @Date 2022/4/29 21:53
 * @Version 1.0
 **/
public class TicketShopDaoImpl implements TicketShopDao {
    /**
     * 查找抵用券集合
     * @param ticketShop 仅拥有条件赋值的抵用券
     * @return 抵用券集合
     * @throws  IllegalAccessException 非法访问
     * @throws SQLException sql error
     * @throws NoSuchFieldException 没有对应的实体类成员
     * @throws InstantiationException
     */
    @Override
    public List<TicketShop> select(TicketShop ticketShop) throws IllegalAccessException,
            SQLException, NoSuchFieldException, InstantiationException {
        System.out.println(GenerateSql.getInstance().select(ticketShop));
        return JdbcUtil.getInstance().selectMore(GenerateSql.getInstance().select(ticketShop), TicketShop.class);
    }

    /**
     * 更新抵用券
     * @param newTicketShop ticket需要更新的值
     * @param  oldTicketShop old ticket
     * @return 成功与否
     * @throws IllegalAccessException
     * @throws SQLException
     */
    @Override
    public int update(TicketShop newTicketShop, TicketShop oldTicketShop) throws IllegalAccessException, SQLException {
        return JdbcUtil.getInstance().insertOrUpdate(GenerateSql.getInstance().update(newTicketShop,oldTicketShop));
    }

    /**
     * 插入抵用券
     * @param ticketShop 新抵用券
     * @return 更新条数
     * @throws IllegalAccessException
     * @throws SQLException
     */
    @Override
    public int insert(TicketShop ticketShop) throws IllegalAccessException, SQLException {
        return JdbcUtil.getInstance().insertOrUpdate(GenerateSql.getInstance().insert(ticketShop));
    }
}
